package com.wanpinghui.wphlibrary.model.object.bean;

import com.wanpinghui.wphlibrary.WPHSdk;
import com.wanpinghui.wphlibrary.model.oauth.OAuthService;
import com.wanpinghui.wphlibrary.model.oauth.bean.BaseUserBean;
import com.wanpinghui.wphlibrary.model.object.constant.DemandType;
import com.wanpinghui.wphlibrary.model.object.constant.ObjectStatus;
import com.wanpinghui.wphlibrary.model.object.constant.ParticipationStatus;
import com.yunshl.yunshllibrary.utils.TextUtil;

import java.util.List;

/***
 * 功能描述:项目详情
 * 作者:qiujialiu
 * 时间:2017/11/23
 ***/

public class ObjectDetailBean {
    public static final int MAX_SUCCESS_COUNT = 2;
    private DemandBean demand;
    private BaseUserBean user;
    /**
     * demand : 需求信息
     * user : 项目所属客户信息
     * supplier_partic_status : 0  // 参与状态，10：排队中； 110: 竞拍成功但未联系; 120: 竞拍成功但余额不足; 130: 超时未联系； 200：抢单成功；300：聊过天；
     * my_offer : 我的报价
     * partic_at : 12332232
     * feedback_info : 反馈信息
     * user_finish_img_info ://当前用户上传结项图片信息
     * demand_finish_img_info : //审核通过的项目结项图片信息
     * "my_follow_type": 2,      // 我的跟进状态. 1-独家锁定 2-继续跟进 3-取消跟进
     * "bid_win_at": 0        // 竞价成功时间戳.  如果是0则表示未中标
     * has_demand_locked: bool,      //项目是否被独家锁定
     * "leave_bid_point": 179,   // 登录用户的剩余汇币
     *  "partic_demand_status":  10 // 派单中: 9; 竞价中:10;   竞价结束（不能再竞价）:15;  二次竞价中: 20;
     */

    private int supplier_partic_status;
    private int my_offer;
    private int partic_at;
    private FeedbackInfoBean feedback_info;
    private UserFinishImgInfoBean user_finish_img_info;
    private DemandFinishImgInfoBean demand_finish_img_info;
    private List<FollowRecordBean> follow_records;
    private int my_follow_type;
    private long bid_win_at;
    private boolean has_demand_locked;
    private int type;//本地字段，记录当前项目状态
    private int leave_bid_point;
    private int partic_demand_status;
    private boolean is_training;
    private int price;
    private List<ParticipationBean> particList;

    public DemandBean getDemand() {
        return demand;
    }

    public void setDemand(DemandBean demand) {
        this.demand = demand;
    }

    public BaseUserBean getUser() {
        return user;
    }

    public void setUser(BaseUserBean user) {
        this.user = user;
    }

    public int getSupplier_partic_status() {
        return supplier_partic_status;
    }

    public void setSupplier_partic_status(int supplier_partic_status) {
        this.supplier_partic_status = supplier_partic_status;
    }

    public int getMy_follow_type() {
        return my_follow_type;
    }

    public int getPartic_demand_status() {
        return partic_demand_status;
    }

    public int getMy_offer() {
        return my_offer;
    }

    public void setMy_offer(int my_offer) {
        this.my_offer = my_offer;
    }

    public int getPartic_at() {
        return partic_at;
    }

    public void setPartic_at(int partic_at) {
        this.partic_at = partic_at;
    }

    public FeedbackInfoBean getFeedback_info() {
        return feedback_info;
    }

    public void setFeedback_info(FeedbackInfoBean feedback_info) {
        this.feedback_info = feedback_info;
    }

    public int getLeave_bid_point() {
        return leave_bid_point;
    }

    public UserFinishImgInfoBean getUser_finish_img_info() {
        return user_finish_img_info;
    }

    public void setUser_finish_img_info(UserFinishImgInfoBean user_finish_img_info) {
        this.user_finish_img_info = user_finish_img_info;
    }

    public DemandFinishImgInfoBean getDemand_finish_img_info() {
        return demand_finish_img_info;
    }

    public void setDemand_finish_img_info(DemandFinishImgInfoBean demand_finish_img_info) {
        this.demand_finish_img_info = demand_finish_img_info;
    }

    public boolean isIs_training() {
        return is_training;
    }

    public boolean isHas_demand_locked() {
        return has_demand_locked;
    }

    public List<FollowRecordBean> getFollow_records() {
        return follow_records;
    }

    public long getBid_win_at() {
        return bid_win_at;
    }

    public List<ParticipationBean> getParticList() {
        return particList;
    }

    public void setParticList(List<ParticipationBean> particList) {
        this.particList = particList;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getTitle() {
        if (demand == null) {
            return null;
        }
        /**
         * 获取项目当前状态
         * -1无效 1圆满完成 2独家锁定，继续跟进 3取消跟进 4派单超时未联系 5派单请尽快联系
         *  6抢单轮到自己呼叫 7竞拍成功未轮到自己呼叫 8分配中 9抢单结束 10 竞标结束  11竞拍成功自己已呼叫
         *  12竞价结束未参与 13一口价竞价中 14免费竞价中 15竞价中 16排队中 17超时未联系 18抢单轮到自己呼叫汇币不足
         *  19抢单但出局
         * @return
         */
         int status = getCurrentStatus();
        if ((demand.getStatus() == ObjectStatus.STATUS_BID_FINISH || demand.getStatus() == ObjectStatus.STATUS_BID_SECOND || demand.getStatus() == ObjectStatus.STATUS_FREE_BIDDING) &&
                (getSupplier_partic_status() == ParticipationStatus.OFFER_SUCCESS_NO_ATTACH || getSupplier_partic_status() == ParticipationStatus.OFFER_SUCCESS_NO_FUND)) {
            return "请尽快联系";
        }else if (demand.getStatus() == ObjectStatus.STATUS_BIDDING && demand.getTag() == 110) {
            return "请尽快联系";
        }else if ((demand.getStatus() == ObjectStatus.STATUS_BID_FINISH || demand.getStatus() == ObjectStatus.STATUS_BID_SECOND
                || demand.getStatus() == ObjectStatus.STATUS_FREE_BIDDING) && getSupplier_partic_status() == ParticipationStatus.QUEUING) {
            return "正在排队";
        }else if (demand.getStatus() == ObjectStatus.STATUS_COMPLETE) {
            return "项目结束";
        }else if (demand.getStatus() == ObjectStatus.STATUS_ORDER_FINISH && demand.getCate() != DemandType.TYPE_BUY) {
            return "抢单结束";
        }else if (demand.getStatus() == ObjectStatus.STATUS_ORDER_FINISH && demand.getCate() == DemandType.TYPE_BUY) {
            return "竞标结束";
        }else if (demand.getStatus() == ObjectStatus.STATUS_BID_FINISH && (getSupplier_partic_status() == 0 || getSupplier_partic_status() == ParticipationStatus.ATTACHED || getSupplier_partic_status() == ParticipationStatus.OVERTIME_NO_ATTACH)) {
            return "竞价结束";
        }else if (getSupplier_partic_status() == ParticipationStatus.OVERTIME_NO_ATTACH) {
            return "超时未联系";
        }else if ((getSupplier_partic_status() != ParticipationStatus.OVERTIME_NO_ATTACH) && getPartic_demand_status() == 9) {
            return "请尽快联系";
        }else if (status == 6 || status==7 || status==18 || status==20){
            return "请尽快联系";
        }else {
            return "等待报价";
        }
    }

    /**
     * 获取项目当前状态
     * -1无效 1圆满完成 2独家锁定，继续跟进 3取消跟进 4派单超时未联系 5派单请尽快联系
     *  6抢单轮到自己呼叫 7竞拍成功未轮到自己呼叫 8分配中 9抢单结束 10 竞标结束  11竞拍成功自己已呼叫
     *  12竞价结束未参与 13一口价竞价中 14免费竞价中 15竞价中 16排队中 17超时未联系 18汇币不足
     *  19抢单但出局 20送单
     * @return
     */
    public int getCurrentStatus() {
        if (demand.getStatus() == ObjectStatus.STATUS_INVALID) {
            type = -1;
        }else if (demand.getStatus() == ObjectStatus.STATUS_COMPLETE) {
            type = 1;
        }else if (getMy_follow_type() == 1 || getMy_follow_type() == 2) {
            type = 2;
        }else if (getMy_follow_type() == 3) {
            type = 3;
        }else if (getSupplier_partic_status() == ParticipationStatus.OVERTIME_NO_ATTACH ) { //派单超时未联系，true为以后是否是派单
            type = 4;
        }else if ((getSupplier_partic_status() != ParticipationStatus.OVERTIME_NO_ATTACH) && getPartic_demand_status() == 9) {
            type = 5;
        }else if (is_training && TextUtil.isNotEmpty(getUser().getMobile())) {
            type = 20;
        }
        //add by xiongning begin
        else if(getSupplier_partic_status() == ParticipationStatus.OFFER_SUCCESS_NO_FUND){
            type = 18;
        }
        //add by xiogning end
        else if (((demand.getStatus() == ObjectStatus.STATUS_BID_FINISH || demand.getStatus() == ObjectStatus.STATUS_BID_SECOND || demand.getStatus() == ObjectStatus.STATUS_FREE_BIDDING || demand.getStatus() == ObjectStatus.STATUS_ORDER_FINISH) &&
                (getSupplier_partic_status() == ParticipationStatus.OFFER_SUCCESS_NO_ATTACH || getSupplier_partic_status() == ParticipationStatus.OFFER_SUCCESS_NO_FUND || getSupplier_partic_status() == ParticipationStatus.ATTACHING))) {
            if (getSupplier_partic_status() == ParticipationStatus.ATTACHING) {
                type = 6;
            }else {
                type = 2;
            }
        }else if ((demand.getStatus() == ObjectStatus.STATUS_BID_FINISH || demand.getStatus() == ObjectStatus.STATUS_BID_SECOND || demand.getStatus() == ObjectStatus.STATUS_FREE_BIDDING)&&
                (getSupplier_partic_status() == ParticipationStatus.BID_SUCCESS)){
            type = 11;
        }else if (demand.getStatus() == ObjectStatus.STATUS_ALLOTTING) {
            type = 8;
        }else if (demand.getStatus() == ObjectStatus.STATUS_ORDER_FINISH ) {
            type = 9;
        }else if (demand.getStatus() == ObjectStatus.STATUS_ORDER_FINISH ) {
            //竞标结束
            type = 10;
        }else if (demand.getStatus() == ObjectStatus.STATUS_BID_FINISH && getSupplier_partic_status() == 0) {
            type = 12;
        }else if ((demand.getStatus() == ObjectStatus.STATUS_BID_FINISH || demand.getStatus() == ObjectStatus.STATUS_BID_SECOND
                || demand.getStatus() == ObjectStatus.STATUS_FREE_BIDDING) && (getSupplier_partic_status() == ParticipationStatus.QUEUING || getSupplier_partic_status() == ParticipationStatus.ATTACHED)) {
            type = 16;
        }else if (demand.getStatus() == ObjectStatus.STATUS_BID_SECOND) {
            type = 13;
        }else if (demand.getStatus() == ObjectStatus.STATUS_FREE_BIDDING) {
            type = 14;
        }else if (demand.getStatus() == ObjectStatus.STATUS_BID_FINISH && getSupplier_partic_status() == ParticipationStatus.OVERTIME_NO_ATTACH) {
            type = 17;
        }else {
            type = 15;
        }
        return type;
    }

    public int getType() {
        if (type == 0) {
            getTitle();
        }
        return type;
    }
}
